package com.hnu.highlynewapp.service.impl;

import com.hnu.highlynewapp.entity.PolicyEntity;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnu.highlynewapp.utils.PageUtils;
import com.hnu.highlynewapp.utils.Query;

import com.hnu.highlynewapp.dao.PolicyAnalyseDao;
import com.hnu.highlynewapp.entity.PolicyAnalyseEntity;
import com.hnu.highlynewapp.service.PolicyAnalyseService;
import org.springframework.util.StringUtils;


@Service("policyAnalyseService")
public class PolicyAnalyseServiceImpl extends ServiceImpl<PolicyAnalyseDao, PolicyAnalyseEntity> implements PolicyAnalyseService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<PolicyAnalyseEntity> page = this.page(
                new Query<PolicyAnalyseEntity>().getPage(params),
                new QueryWrapper<PolicyAnalyseEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<PolicyAnalyseEntity> listByCondition(String category) {
        QueryWrapper<PolicyAnalyseEntity> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(category)) {
            wrapper.eq("category", category);
        }
        wrapper.orderByDesc("publish_time");
        List<PolicyAnalyseEntity> list = baseMapper.selectList(wrapper);
        return list;
    }

}